using System;
using System.Windows;
using Giraffe.Client.Common;
using Giraffe.Client.MainWindowModule.ClientsPanel;
using Giraffe.Client.MainWindowModule.Contacts;
using Giraffe.Client.MainWindowModule.Resources;
using Giraffe.Client.MainWindowModule.Views;
using Giraffe.Core.Common;
using Giraffe.Core.Common.Messengers;
using Giraffe.Core.Model;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Giraffe.Client.Common.Constants;

namespace Giraffe.Client.MainWindowModule
{
    public class MainWindowModule: IModule
    {
        private readonly IRegionManager regionManager;

        public MainWindowModule(IRegionManager regionManager)
        {
            this.regionManager = regionManager;
        }

        public void Initialize()
        {
            LoadResources();

            IRegion statusBarRegion = regionManager.Regions[RegionNames.MainToolBar];
            statusBarRegion.Add(new MessengerListViewModel(ObjectProvider.Resolve<IUser>()));

            IRegion contactsRegion = regionManager.Regions[RegionNames.MainContacts];
            contactsRegion.Add(new ContactListViewModel(ObjectProvider.Resolve<IUser>()));
        }

        private void LoadResources()
        {
            var localResourcesDict = new DataTemplateDictionary();
            var app = ObjectProvider.Resolve<IApplicationProxy>();
            app.Resources.MergedDictionaries.Add(localResourcesDict);
        }
    }
}